package com.tianji.promotion.controller;


import com.tianji.common.domain.dto.PageDTO;
import com.tianji.promotion.domain.dto.CouponFormDTO;
import com.tianji.promotion.domain.dto.CouponIssueFormDTO;
import com.tianji.promotion.domain.query.CouponQuery;
import com.tianji.promotion.domain.vo.CouponDetailVO;
import com.tianji.promotion.domain.vo.CouponPageVO;
import com.tianji.promotion.domain.vo.CouponVO;
import com.tianji.promotion.service.ICouponService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 优惠券的规则信息 前端控制器
 * </p>
 *
 * @author rui
 * @since 2024-08-05
 */
@RestController
@RequestMapping("/coupons")
@RequiredArgsConstructor
@Api(tags = "优惠券相关接口")
public class CouponController {
    private final ICouponService couponService;
    @ApiOperation("发放优惠券")
    @PutMapping("/{id}/issue")
    public void addCoupon(@PathVariable("id") Long id,@RequestBody @Validated CouponIssueFormDTO dto){
        couponService.addCoupon(id,dto);
    }
    @ApiOperation("新增优惠券")
    @PostMapping
    public void saveCoupon(@RequestBody @Validated CouponFormDTO formDTO){
        couponService.saveCoupon(formDTO);
    }

    @ApiOperation("分页查询优惠券")
    @GetMapping("/page")
    public PageDTO<CouponPageVO> pageQueryCoupon(CouponQuery query){
            return couponService.pageQueryCoupon(query);
    }
    @ApiOperation("修改优惠券")
    @PutMapping("/{id}")
    public void updateCoupon(@PathVariable("id") Long id,@RequestBody @Validated CouponFormDTO dto){
        couponService.updateCoupon(id,dto);
    }
    @ApiOperation("删除优惠券")
    @DeleteMapping("/{id}")
    public void deleteCoupon(@PathVariable("id") Long id){
        couponService.deleteCoupon(id);
    }
    @ApiOperation("查询优惠券")
    @GetMapping("/{id}")
    public CouponDetailVO queryCoupon(@PathVariable("id") Long id){
        return couponService.queryCoupon(id);
    }

    @ApiOperation("暂停发放优惠券")
    @PutMapping("/{id}/pause")
    public void pauseCouponByStatus(@PathVariable("id") Long id){
        couponService.pauseCouponByStatus(id);
    }

    @ApiOperation("查询发放中的优惠券-用户端")
    @GetMapping("/list")
    public List<CouponVO> queryUserCouponByList(){
        return couponService.queryUserCouponByList();
    }
}
